package com.hc.pingtan.conf;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class ImageReplace {
    @Value("${image.shopxo}")
    private String shopxoImagePrefix;

    public String shopxoImageReplace(String str) {
        return str.replaceAll("/static/upload/images/goods/", shopxoImagePrefix + "/static/upload/images/goods/");
    }

    public <T> T shopxoImageReplace(Object obj, TypeReference<T> typeReference) {
        String jsonString = JSON.toJSONString(obj);
        String json = jsonString.replaceAll("/static/upload/images/", shopxoImagePrefix + "/static/upload/images/");
        return JSON.parseObject(json, typeReference);
    }
}
